package com.netstar.util;

public class Status {
	private long bytesTotalRead;

	/*
	 * In ms
	 */
	private long timeEclipse;

	public synchronized void clear() {
		bytesTotalRead = 0;
		timeEclipse = 0;
	}

	/**
	 * Return 0 if speed is not unknown
	 */
	public synchronized float getSpeed() {
		if (0 != timeEclipse) {
			return (float) bytesTotalRead / timeEclipse * 8;
		}
		return 0;
	}

	public synchronized void setProp(long bytes, long time) {
		bytesTotalRead = bytes;
		timeEclipse = time;
	}

	public void copyFrom(Status status) {
		bytesTotalRead = status.bytesTotalRead;
		timeEclipse = status.timeEclipse;
	}

	@Override
	public String toString() {
		return "bytes=" + bytesTotalRead + ", time=" + timeEclipse;
	}

}